

class Test {
//    统计字符串中的单词个数，这里的单词指的是连续的不是空格的字符。
//    请注意，你可以假定字符串里不包括任何不可打印的字符。
//    示例:
//    输入: "Hello, my name is John"
//    输出: 5
//    解释: 这里的单词是指连续的不是空格的字符，所以 "Hello," 算作 1 个单词
        public static int countSegments(String s) {
            if(s == null || s.length() == 0) {
                return 0;
            }
            String[] str = s.split(" ");
            int count = 0;
            for(String x : str) {
                if(x.length() != 0) {
                    count++;
                }
            }
            return count;
        }

    public static void main1(String[] args) {
        int ret = countSegments("Hello, my name is John");
        System.out.println(ret);
    }

    public static String toLowerCase(String s) {
            String ret = "";
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(ch >= 'A' && ch <= 'Z') {
                char tmp = (char)(ch + 32);
                ret = ret + tmp;
            }else {
                ret = ret + ch;
            }
        }
        return ret;
    }
    public static String toLowerCase2(String s) {
        StringBuilder ret = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(ch >= 'A' && ch <= 'Z') {
                char tmp = (char)(ch + 32);
                ret.append(tmp);
            }else {
                ret.append(ch);
            }
        }
        return ret.toString();
    }
    public static int add(int a, int b) {
            return a+b;
    }
    public static int add(int a, int b, int c) {
            return a+b+c;
    }
    //可变参数 代码的阅读性不高
    public static int add(int...array) {
            int ret = 0;
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
        }
        return ret;
    }
    public static void main(String[] args) {
            int[] array = {1,2,3};
        System.out.println(add(array));
        System.out.println(add(1,2,3,4,5,6));

    }

}